package com.lovo.utils;

import com.lovo.enums.UserCodeEnum;
import com.lovo.vo.ResultVO;

/**
 * @title 表现层结果集对象工厂
 * @author: luo
 * @date: 2020/11/17 20:33
 */
public class ResultFactory {

    /**
     *携带数据的成功构造
     * @param data 携带的数据
     * @return
     */
    public static ResultVO success(Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(true);
        resultVO.setCode(1000);
        resultVO.setMsg("操作成功");
        resultVO.setData(data);
        return resultVO;
    }

    /**
     *不携带数据的成功构造
     * @return
     */
    public static ResultVO success(){
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(true);
        resultVO.setCode(1000);
        resultVO.setMsg("操作成功");
        return resultVO;
    }

    /**
     * 失败时返回的构造器
     * @param userCodeEnum 用户状态枚举
     * @return
     */
    public static ResultVO fail(UserCodeEnum userCodeEnum){
        ResultVO resultVO = new ResultVO();
        resultVO.setSuccess(false);
        resultVO.setCode(userCodeEnum.getCode());
        resultVO.setMsg(userCodeEnum.getMsg());
        return resultVO;
    }

}
